# -*- coding: UTF-8 -*-
import urllib2
import mongodbClient
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
from bs4 import BeautifulSoup
def yjfx(url):
    page = urllib2.urlopen(url)
    html_doc = page.read()
    soup = BeautifulSoup(html_doc.decode('gb2312','ignore'))
    for i in soup.findAll('table'):
        tr = i.find_all('tr')
        for a in tr:
            tr = a.find_all('td')
            col=1
            gpcode=""
            gpnamce=""
            zf=""
            ggtime=""
            flag=1
            for b in tr:
                bb=b.text
                bc = bb.encode()
                if col==2:
                    gpcode=bc
                if col==3:
                    gpnamce=bc
                if col==4:
                    if "业绩大幅上升" in bc:
                        flag=0
                if col==6:
                    zf=bc;
                if col==8:
                    ggtime=bc;
                col=col+1

            if flag==0:
                gpcode=gpcode.replace('\n','')
                gpnamce=gpnamce.replace('\n','')
                zf=zf.replace('\n            \t','')
                print(gpnamce)
                mongodbClient.insertYJDZ(gpcode,gpnamce,zf,ggtime)

#yjfx("http://data.10jqka.com.cn/financial/yjyg/date/2017-06-30/board/ALL/field/enddate/order/desc/page/1/ajax/1/")
